#include<stdio.h>
int main()
{

	char string[10] = { 0 };
	scanf("%s", string);
	int j = 0;
	while (string[j] != '\0')
	{
		j++;
	}
	j--;
	int flag = 1;
	long long sum = 0;
	long long x = 1;
	for (j; j >= 0; j--)
	{
		if (flag == 1)
		{
			if (string[j] >= 'A' && string[j] <= 'F')
			{
				switch (string[j])
				{
				case 'A':
					sum += 10;
					break;
				case 'B':
					sum += 11;
					break;
				case 'C':
					sum += 12;
					break;
				case 'D':
					sum += 13;
					break;
				case 'E':
					sum += 14;
					break;
				case 'F':
					sum += 15;
					break;

				}
			}
			else
			{
				sum = sum + (string[j] - '0');
			}
		}
		else
		{

			x *= 16;
			if (string[j] >= 'A' && string[j] <= 'F')
			{
				switch (string[j])
				{
				case 'A':
					sum += 10 * x;
					break;
				case 'B':
					sum += 11 * x;
					break;
				case 'C':
					sum += 12 * x;
					break;
				case 'D':
					sum += 13 * x;
					break;
				case 'E':
					sum += 14 * x;
					break;
				case 'F':
					sum += 15 * x;
					break;

				}
			}
			else
			{
				sum = sum + (string[j] - '0') * x;
			}

		}
		flag = 0;
	}
	printf("%lld", sum);
	return 0;
}
